// Author: Zhang Yisong(zhang_yisong@foxmail.com)

#pragma once
#include "allocator.hpp"
#include "pw_async2/coro.h"
#include "pw_preprocessor/arguments.h"
namespace coro {

class Context : public pw::async2::CoroContext {
public:
  Context(pw::allocator::Allocator &alloc) : pw::async2::CoroContext(alloc){};
#if CONFIG_CORO_GLOBAL_BUFF
  Context() : pw::async2::CoroContext(coro::GetGlobalAllocator()){};
#endif
};

inline auto &GetGlobalContext() {
  static Context ctx{GetGlobalAllocator()};
  return ctx;
}

#define CORO_MEM_CTX(obj, size)                                                \
  CORO_CTX_BUF_DEFINE(m_buff, size)                                            \
  coro::Allocator m_alloc{m_buff};                                             \
  coro::Context obj { m_alloc }

using pw::async2::CoroContext;
} // namespace coro
#define CO_CTX pw::async2::CoroContext &ctx = coro::GetGlobalContext()

